package cn.wolfcode.product.dao.impl;

import cn.wolfcode.product.dao.ProductDAO;
import cn.wolfcode.product.domain.Product;
import cn.wolfcode.product.util.MyBatisUtils;
import org.apache.ibatis.javassist.expr.NewArray;
import org.apache.ibatis.session.SqlSession;

import java.util.Date;
import java.util.List;

public class ProductDAOImpl implements ProductDAO {
    private SqlSession ss= MyBatisUtils.getSqlSession();
    @Override
    public void add(Product product) {
        ss.insert("cn.wolfcode.product.mapper.ProductMapper.add", product);
        ss.commit();
    }

    @Override
    public void update(Product product) {
        ss.update("cn.wolfcode.product.mapper.ProductMapper.update", product);
        ss.commit();

    }

    @Override
    public void delById(Long id) {
        ss.delete("cn.wolfcode.product.mapper.ProductMapper.delById", id);
        ss.commit();

    }

    @Override
    public Product getById(Long id) {
        return ss.selectOne("cn.wolfcode.product.mapper.ProductMapper.getById", id);
    }

    @Override
    public List<Product> getAll() {
        return ss.selectList("cn.wolfcode.product.mapper.ProductMapper.getAll");
    }
}
